#pragma once

#include <glad/glad.h> // 包含glad来获取所有的必须OpenGL头文件
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>

namespace Physical
{
    class Loaction
    {
    private:

    public:

        glm::vec3 position;
        glm::vec3 rotation; // 旋转角度制
        glm::mat4 model;
   

        glm::mat4 GetModel()
        {
            auto rotatex=glm::rotate(glm::mat4(1.0),glm::radians(this->rotation.x),glm::vec3(1.0f, 0.0f, 0.0f));
            auto rotatey=glm::rotate(glm::mat4(1.0),glm::radians(this->rotation.y),glm::vec3(0.0f, 1.0f, 0.0f));
            auto rotatez=glm::rotate(glm::mat4(1.0),glm::radians(this->rotation.z),glm::vec3(0.0f, 0.0f, 1.0f));
            auto transform=glm::translate(glm::mat4(1.0), this->position);
          
            return transform*rotatex*rotatey*rotatez;
        }

     


        Loaction(glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f), 
                 glm::vec3 rotation = glm::vec3(0.0f, 0.0f, 0.0f))
        {
            this->position = position;
            this->rotation = rotation;
        }

        void SetPos(glm::vec3 position)
        {
            this->position = position;
        }

        void SetPos(float x, float y, float z)
        {
            this->position = glm::vec3(x, y, z);
        }


        void SetRotation(glm::vec3 rotation)
        {
            this->rotation = rotation;
        }

        void SetRotation(float x, float y, float z)
        {
            this->rotation = glm::vec3(x, y, z);
        }

        void AddRotation(float x, float y, float z)
        {
            this->rotation += glm::vec3(x, y, z);

            auto fun = [](float x)->float{
                if(x>360.0f)
                    x-=360.0f;
                if(x<0.0f)
                    x+=360.0f;
                return x;
            };

            this->rotation.x = fun(this->rotation.x);
            this->rotation.y = fun(this->rotation.y);
            this->rotation.z = fun(this->rotation.z);
        }

        void AddRotation(glm::vec3 rotation)
        {
            this->rotation += rotation;

            auto fun = [](float x)->float{
                if(x>360.0f)
                    x-=360.0f;
                if(x<0.0f)
                    x+=360.0f;

                return x;
            };

            this->rotation.x = fun(this->rotation.x);
            this->rotation.y = fun(this->rotation.y);
            this->rotation.z = fun(this->rotation.z);

        }

        void AddPos(float x, float y, float z)
        {
            this->position += glm::vec3(x, y, z);
        }

        void AddPos(glm::vec3 position)
        {
            this->position += position;
        }

 
  


        ~Loaction() {}
    };





    class RigidBodyMotion
    {
    public:
        glm::vec3 Velocity;
        glm::vec3 Acceleration;
        glm::vec3 RotateVelocity; // 旋转角度制
        glm::vec3 RotateAcceleration;   
        RigidBodyMotion(/* args */) {
            Velocity = glm::vec3(0.0f, 0.0f, 0.0f);
            Acceleration = glm::vec3(0.0f, 0.0f, 0.0f);
            RotateVelocity = glm::vec3(0.0f, 0.0f, 0.0f);
            RotateAcceleration = glm::vec3(0.0f, 0.0f, 0.0f);
        }

        glm::vec3 UpdatePosition(float deltaTime){
            Velocity += Acceleration * deltaTime;
            return Velocity * deltaTime;
        }
        
        glm::vec3 UpdateRotatePosition(float deltaTime){
            RotateVelocity += RotateAcceleration * deltaTime;
            return RotateVelocity * deltaTime;
        }
        ~RigidBodyMotion() {}
    };
}


